import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {JpushService} from '../jpush.service';
import {Jpush} from '../jpush';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
})
export class ListComponent implements OnInit {


    data: Jpush[] = [];
    pageSize = 10;
    currentPage = 1;
    tatol = 0;

    constructor(
        private jpushService: JpushService,
        private msg: NzMessageService
    ) {
    }

    ngOnInit() {
        this.getlist(this.currentPage);
    }

    getlist($event) {
        this.jpushService.getjpushlist($event - 1).subscribe(res => {
            this.data = res['list'];
            this.tatol = res['totalElement'];
            this.pageSize = res['pageSize'];
            this.currentPage = $event;
        }, __ => {

        });
    }


    del(item) {
        const index = this.data.indexOf(item);
        this.data = [...this.data.slice(0, index), ...this.data.slice(index + 1, this.data.length)];
        this.jpushService.deljpush(item['id']).subscribe(res => {
            this.msg.success('删除成功');
        }, __ => {
            this.jpushService.getjpushlist(this.currentPage - 1);
        });
    }

}
